<style lang="scss" scoped>
  .video-index {

  }
</style>

<template lang="pug">
  .video-index
    video-player.video-player-box(
    :options="playerOptions"
    :playsinline="true"
    customEventName="customstatechangedeventname"
    @play="onPlayerPlay($event)"
    @pause="onPlayerPause($event)"
    @ended="onPlayerEnded($event)"
    @waiting="onPlayerWaiting($event)"
    @playing="onPlayerPlaying($event)"
    @loadeddata="onPlayerLoadeddata($event)"
    @timeupdate="onPlayerTimeupdate($event)"
    @canplay="onPlayerCanplay($event)"
    @canplaythrough="onPlayerCanplaythrough($event)"
    @statechanged="playerStateChanged($event)"
    @ready="playerReadied")
</template>

<script>
  import {mapState, mapGetters, mapMutations} from 'vuex'
  import 'video.js/dist/video-js.css'
  import { videoPlayer } from 'vue-video-player'
  export default {
    name: "video-index",
    data() {
      return {
        playerOptions: {
          // videojs options
          muted: true,
          language: 'en',
          playbackRates: [0.7, 1.0, 1.5, 2.0],
          sources: [{
            type: "video/mp4",
            src: "https://cdn.theguardian.tv/webM/2015/07/20/150716YesMen_synd_768k_vp8.webm"
          }],
          poster: "/static/images/author.jpg",
        }
      }
    },
    computed: {
      ...mapState([]),
      ...mapGetters([]),
      player() {
        return this.$refs.videoPlayer.player
      }
    },
    methods: {
      ...mapMutations([]),
      // listen event
      onPlayerPlay(player) {
        // console.log('player play!', player)
      },
      onPlayerPause(player) {
        // console.log('player pause!', player)
      },
      // ...player event

      // or listen state event
      playerStateChanged(playerCurrentState) {
        // console.log('player current update state', playerCurrentState)
      },

      // player is ready
      playerReadied(player) {
        console.log('找到资源', player)
        // you can use it to do something...
        // player.[methods]
      },
      onPlayerLoadeddata(player){
        console.log('加载资源', player)
      },
      onPlayerCanplay(player){
        console.log('可以播放', player)
      },
      onPlayerCanplaythrough(player){
        console.log('加载完毕', player)
      },
      onPlayerPlaying(player){
        console.log('开始', player)
      },
      onPlayerTimeupdate(player){
        console.log('播放长度改变', player)
      },
      onPlayerWaiting(player){
        console.log('关闭', player)
      }
    },
    created() {

    },
    mounted() {

    },
    components:{
      videoPlayer
    }
  }
</script>

